<?php
/**
 * File khai báo lớp CTemporaryStore
 * 
 * @version 1.0
 * @since June-2008
 * @package lib
 * @subpackage data
 * @name CTemporaryStore
 * @deprecated  Lớp mở rộng từ lớp CStore. Lớp lưu trữ bằng bộ nhớ
*/
class CTemporaryStore extends CStore
{
	public $data;
	public $current_table;
	public $current_condition;
	function __construct($data = array())
	{
		$this->data = $data;
		parent::__construct();
	}
	function select($table, $condition = false, $options = array())
	{
		$this->current_table = $table;
		$this->current_condition = $condition;
		$current = reset($this->data[$table]);
		while($current and !CRecord($current)->test($condition))
		{
			$current = next($this->data[$table]);
		}
		return $current;
	}
	function select_all($table, $condition = false, $options = array())
	{
		$current = reset($this->data[$table]);
		$result_items = array();
		while($current)
		{
			if(CRecord($current)->test($condition))
			{
				$result_items[] = $current;
			}
			$current = next($this->data[$table]);
		}
		return $result_items;
	}
	function fetch($query_string = false)
	{
		while($current = next($this->data[$this->current_table]))
		{
			if(CRecord($current)->test($condition))
			{
				return $current;
			}
			$current = next($this->data[$this->current_table]);
		}
	}
	function insert($table, $values)
	{
		$this->data[$table][] = $values;
	}
	function update($table, $values, $condition)
	{
		$current = reset($this->data[$table]);
		while($current)
		{
			if(CRecord($current)->test($condition))
			{
				foreach($values as $key=>$value)
				{
					$this->data[$table][key($this->data[$table])][$key] = $value;
				}
			}
			$current = next($this->data[$table]);
		}
	}
	function delete($table, $condition)
	{
		$current = reset($this->data[$table]);
		while($current)
		{
			if(CRecord($current)->test($condition))
			{
				unset($this->data[$table][key($this->data[$table])]);
			}
			$current = next($this->data[$table]);
		}
	}
}
function CTemporaryStore()
{
	return new CTemporaryStore();
}
?>